package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.MySmokeInfo;
import com.ruoyi.system.service.IMySmokeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 卷烟基础信息Controller
 * 
 * @author ruoyi
 * @date 2025-01-14
 */
@RestController
@RequestMapping("/system/info")
public class MySmokeInfoController extends BaseController
{
    @Autowired
    private IMySmokeInfoService mySmokeInfoService;

    /**
     * 查询卷烟基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(MySmokeInfo mySmokeInfo)
    {
        startPage();
        List<MySmokeInfo> list = mySmokeInfoService.selectMySmokeInfoList(mySmokeInfo);
        return getDataTable(list);
    }

    /**
     * 导出卷烟基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "卷烟基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MySmokeInfo mySmokeInfo)
    {
        List<MySmokeInfo> list = mySmokeInfoService.selectMySmokeInfoList(mySmokeInfo);
        ExcelUtil<MySmokeInfo> util = new ExcelUtil<MySmokeInfo>(MySmokeInfo.class);
        util.exportExcel(response, list, "卷烟基础信息数据");
    }

    /**
     * 获取卷烟基础信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mySmokeInfoService.selectMySmokeInfoById(id));
    }

    /**
     * 新增卷烟基础信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "卷烟基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MySmokeInfo mySmokeInfo)
    {
        return toAjax(mySmokeInfoService.insertMySmokeInfo(mySmokeInfo));
    }

    /**
     * 修改卷烟基础信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "卷烟基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MySmokeInfo mySmokeInfo)
    {
        return toAjax(mySmokeInfoService.updateMySmokeInfo(mySmokeInfo));
    }

    /**
     * 删除卷烟基础信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "卷烟基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mySmokeInfoService.deleteMySmokeInfoByIds(ids));
    }
}
